<html>
<head>
<style type="text/css">
#stage TR{
	height: 24px;	
}
#stage TD{
	width: 24px;
}
.empty {
	background-color: silver;
}
.active {
	background-color: lime;
}
</style>
<script type="text/javascript">
var S =   [ [0,1,1], [0,1,1] ] ;
var LL1 = [ [1,1,1], [0,0,1] ] ;
var LL2 = [ [0,1] , [0,1], [1,1] ];
var LL3 = [ [1,0,0], [1,1,1] ];
var LL4 = [ [1,1], [1,0], [1,0] ];

var LR1 = [ [1,1,1], [1,0,0] ] ;
var LR2 = [ [1,1], [0,1], [0,1] ];
var LR3 = [ [0,0,1], [1,1,1] ];
var LR4 = [ [1,0], [1,0], [1,1] ];

var ZL1 = [ [1,1], [0,1,1] ];
var ZL2 = [ [0,1], [1,1], [1,0] ];

var ZR1 = [ [0,1,1], [1,1] ];
var ZR2 = [ [1], [1,1], [0,1] ];

var B1  = [ [1,1,1,1] ];
var B2  = [ [1],[1],[1],[1] ];
var P = [ [S], [LL1,LL2,LL3,LL4], [LR1,LR2,LR3,LR4], [ZL1,ZL2], [ZR1,ZR2], [B1,B2] ];

function init(stage){
	for(var i=0;i<40;i++){
		var tr = document.createElement("TR");
		stage[i]=[];
		for(var j=0;j<10;j++){
			var td = document.createElement("TD");
			td.className = "empty";
			tr.appendChild(td);	
			stage[i][j] = td;
		}
		stage.appendChild(tr);
	}
}
function put(_stage, _p, _i, _j){
	for(var i=0;i<_p.length; i++){
		for(var j = 0; j<_p[i].length; j++){
			if(_p[i][j] == 1){
				_stage[_i+i][_j+j].className = "active";
			}
		}
	}
}

function nextP(){
	var rand = Math.random();
	rand = Math.round(rand*10000);
	var idx = rand%(P.length);
	var idx2 = rand%(P[idx].length);
	return P[idx][idx2];
}
var y=0;
function movedown(_stage, _p, _i, _j){
	for(var i=0;i<_p.length; i++){
		for(var j = 0; j<_p[i].length; j++){
			if(_p[i][j] == 1){
				_stage[_i+i][_j+j].className = "empty";
			}
		}
	}
	alert(1);
	for(var i=0;i<_p.length; i++){
		for(var j = 0; j<_p[i].length; j++){
			if(_p[i][j] == 1){
				_stage[_i+i+1][_j+j].className = "active";
			}
		}
	}


	y++;
}
</script>
</head>
<body>
<table id="stage"></table>
<script type="text/javascript">
var stage = document.getElementById("stage");
var game = [];
init(stage);

var p = nextP();
put(stage, p, 0, 0);

function movedown1(){
	movedown(stage, p, y, 0);
	y++;
}

window.setInterval(movedown1,200,stage,p,y,0);


</script>
</body>
</html>